/*
 *说明：访问控制申请表 首页脚本
 *
 *@author mlc 2013-04-07
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'节点名称',field:'node_decode',align:'center',width:80},

            {title:'工单号',field:'order_id',align:'center',width:80},

            {title:'工单状态',field:'order_status_decode',align:'center',width:40},

            {title:'资源组名称',field:'rsc_grp_name',align:'center',width:80},
            
            {title:'资源名称',field:'rsc_name',align:'center',width:100},

            {title:'资源账号',field:'rsc_acc_name',align:'center',width:80},
            
            {title:'协议',field:'rsc_pro_name',align:'center',width:60},
            
            {title:'端口',field:'rsc_pro_port',align:'center',width:40},

            {title:'运维目的',field:'operation_type_decode',align:'center',width:50},
            
            {title:'开始时间',field:'start_time',align:'center',width:100},
            
            {title:'有效期(分钟)',field:'available_length',align:'center',width:60},

            {title:'策略名称',field:'policy_name',align:'center',width:100}
        ]]
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);
	$('#deleteBtn').click(deleteOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'P_WF_ACL_APPLY!showList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(fid) {

	var href = 'P_WF_ACL_APPLY!showInfo.do?model.key=' + fid;
	openWin(href,'pop',editWindowWidth,editWindowHeight); 
}

//添加访问控制申请表
function addOperation(){
	var node_id = $('#node_id').val();
	var url = '';
	if(node_id != null){
		url = 'P_WF_ACL_APPLY!showUsrNotApplyedRsc.do?firstQuery=true&model.node_id=' + node_id;
	}else{
		url = 'P_WF_ACL_APPLY!showUsrNotApplyedRsc.do?firstQuery=true';
	}
	openWin(url, 'pop', 'A0', '1150', '755');
}

//我的访问控制权限
function editOperation(){  
	var node_id = $('#node_id').val();
	var href = 'P_WF_ACL_APPLY!showUsrAuthRscIndex.do?model.node_id=' + node_id;
	openWin(href,'pop', 'A0', '1150', '755');
}   

//删除访问控制申请表
function deleteOperation() {

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];

	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}

	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'P_WF_ACL_APPLY!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}